package shthon2011s.eroid.ranking;

import shthon2011s.eroid.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;

public class RankingAdapter extends BaseAdapter {
    private static final String[] NAMES = new String[]{"YAMAZAKI Makoto","Toyoaki Oko(パトラッシュ)","Toyoaki Oko(パトラッシュ)","Kazuhito Kawai（川合和史）","kobayashi-taro","とみた ちひろ","さきら","ばりとん","KUGO","YAMAZAKI Makoto","hammer.mule","とみた ちひろ","とみた ちひろ","まつも","KUGO","Masahide Fukagawa","英吉","ばりとん","Masahide Fukagawa","英吉","itog","八木","hammer.mule","松原和也はうごきますん","Rie Seguchi","れいぶん","ばりとん","Yuki Anzai","八木","Toyoaki Oko(パトラッシュ)","塚田 翔也","とみた ちひろ","さきら","Tam","Toyoaki Oko(パトラッシュ)","れいぶん","hammer.mule","Toyoaki Oko(パトラッシュ)","松原和也はうごきますん","まつも","ばりとん","Toyoaki Oko(パトラッシュ)","hammer.mule","塚田 翔也","Kazuhito Kawai（川合和史）","Rie Seguchi","itog","英吉","まつも","Rie Seguchi","kobayashi-taro","松原和也はうごきますん","さきら","ばりとん","Yuki Anzai","塚田 翔也","松原和也はうごきますん","八木","さきら","itog","さきら","八木","Tam","Kazuhito Kawai（川合和史）","さきら","Yuki Anzai","れいぶん","kobayashi-taro","とみた ちひろ","YAMAZAKI Makoto","ばりとん","itog","itog","Masahide Fukagawa","まつも","Rie Seguchi","八木","とみた ちひろ","Toyoaki Oko(パトラッシュ)","Yuki Anzai","Masahide Fukagawa","Kazuhito Kawai（川合和史）","kobayashi-taro","Yuki Anzai","kobayashi-taro","塚田 翔也","ばりとん","Kazuhito Kawai（川合和史）","れいぶん","まつも","八木","Masahide Fukagawa","kobayashi-taro","kobayashi-taro","まつも","hammer.mule","八木","さきら","Rie Seguchi","Yuki Anzai","とみた ちひろ","Rie Seguchi","まつも","Yuki Anzai","Toyoaki Oko(パトラッシュ)","YAMAZAKI Makoto","KUGO","Tam","Tam","Toyoaki Oko(パトラッシュ)","hammer.mule","松原和也はうごきますん","hammer.mule","まつも","Tam","Kazuhito Kawai（川合和史）","れいぶん","Rie Seguchi","松原和也はうごきますん","itog","KUGO","塚田 翔也","Rie Seguchi","itog","Masahide Fukagawa","Masahide Fukagawa","Tam","Tam","hammer.mule","れいぶん","英吉","KUGO","とみた ちひろ","英吉","kobayashi-taro","Tam","塚田 翔也","YAMAZAKI Makoto","れいぶん","Kazuhito Kawai（川合和史）","英吉","Yuki Anzai","itog","KUGO","hammer.mule","塚田 翔也","KUGO","kobayashi-taro","塚田 翔也","Masahide Fukagawa","Masahide Fukagawa","Masahide Fukagawa","塚田 翔也","れいぶん","ばりとん","KUGO","Rie Seguchi","KUGO","YAMAZAKI Makoto","松原和也はうごきますん","れいぶん","さきら","八木","八木","Tam","Tam","英吉","松原和也はうごきますん","YAMAZAKI Makoto","Yuki Anzai","KUGO","hammer.mule","Kazuhito Kawai（川合和史）","松原和也はうごきますん","itog","Rie Seguchi","まつも","itog","英吉","YAMAZAKI Makoto","塚田 翔也","kobayashi-taro","ばりとん","とみた ちひろ","Kazuhito Kawai（川合和史）","Yuki Anzai","YAMAZAKI Makoto","Toyoaki Oko(パトラッシュ)","英吉","さきら","八木","英吉","Kazuhito Kawai（川合和史）","ばりとん","松原和也はうごきますん","YAMAZAKI Makoto","れいぶん","まつも","さきら","とみた ちひろ"};
    private static final float[] CALS = new float[] {699481.201171875f,697973.6328125f,697882.080078125f,697448.73046875f,696380.615234375f,695129.39453125f,693652.34375f,693499.755859375f,692565.91796875f,690985.107421875f,688604.736328125f,688372.802734375f,688214.111328125f,687072.75390625f,686639.404296875f,685729.98046875f,684484.86328125f,684265.13671875f,682031.25f,680236.81640625f,679113.76953125f,678778.076171875f,678393.5546875f,677319.3359375f,675933.837890625f,674481.201171875f,674237.060546875f,673797.607421875f,671862.79296875f,671405.029296875f,670538.330078125f,669396.97265625f,668994.140625f,668353.271484375f,667437.744140625f,667321.77734375f,667144.775390625f,667108.154296875f,666680.908203125f,665570.068359375f,665252.685546875f,663787.841796875f,663140.869140625f,659954.833984375f,658831.787109375f,658502.197265625f,657104.4921875f,656768.798828125f,656115.72265625f,655895.99609375f,655560.302734375f,652819.82421875f,650128.173828125f,649310.302734375f,648785.400390625f,647827.1484375f,647790.52734375f,647741.69921875f,647558.59375f,644714.35546875f,644635.009765625f,644580.078125f,643084.716796875f,642486.572265625f,641632.080078125f,640753.173828125f,640026.85546875f,639343.26171875f,638970.947265625f,638323.974609375f,637744.140625f,637542.724609375f,637243.65234375f,636895.751953125f,636834.716796875f,635961.9140625f,631536.865234375f,631170.654296875f,630303.955078125f,630279.541015625f,630236.81640625f,628686.5234375f,628576.66015625f,628405.76171875f,628320.3125f,627813.720703125f,626440.4296875f,625701.904296875f,625231.93359375f,624493.408203125f,623651.123046875f,623504.638671875f,621386.71875f,621221.923828125f,621081.54296875f,620196.533203125f,619708.251953125f,619622.802734375f,617431.640625f,616662.59765625f,611724.853515625f,610406.494140625f,610089.111328125f,609790.0390625f,607336.42578125f,607244.873046875f,605090.33203125f,604089.35546875f,603320.3125f,602038.57421875f,599963.37890625f,599938.96484375f,597668.45703125f,596636.962890625f,596490.478515625f,595910.64453125f,594744.873046875f,594390.869140625f,593493.65234375f,593481.4453125f,591864.013671875f,591632.080078125f,591156.005859375f,590319.82421875f,589105.224609375f,588830.56640625f,588665.771484375f,587231.4453125f,585937.5f,584924.31640625f,584344.482421875f,582781.982421875f,581964.111328125f,581243.896484375f,580963.134765625f,580120.849609375f,578979.4921875f,576910.400390625f,575756.8359375f,574975.5859375f,573248.291015625f,572680.6640625f,572332.763671875f,571875f,569549.560546875f,569061.279296875f,566412.353515625f,563903.80859375f,563574.21875f,561859.130859375f,558410.64453125f,557830.810546875f,557287.59765625f,555664.0625f,555261.23046875f,550994.873046875f,548919.677734375f,547979.736328125f,543792.724609375f,541156.005859375f,540783.69140625f,540350.341796875f,540295.41015625f,538751.220703125f,538012.6953125f,536810.302734375f,536138.916015625f,534747.314453125f,534106.4453125f,533605.95703125f,530847.16796875f,530627.44140625f,529467.7734375f,527459.716796875f,526489.2578125f,526477.05078125f,525238.037109375f,524963.37890625f,523907.470703125f,523114.013671875f,521582.03125f,520092.7734375f,519512.939453125f,519348.14453125f,519018.5546875f,517382.8125f,517144.775390625f,517041.015625f,516754.150390625f,515411.376953125f,514929.19921875f,512738.037109375f,512390.13671875f,512286.376953125f,510845.947265625f,508746.337890625f,507434.08203125f,506365.966796875f,505895.99609375f,502917.48046875f};
    private static final int LENGTH = NAMES.length;
    private static final ArrayList<RankingItem> ITEMS = new ArrayList<RankingItem>(LENGTH);
    // make mock data
    {
        for (int i = 0; i < LENGTH; ++i) {
            ITEMS.add(new RankingItem(i + 1, NAMES[i], CALS[i]));
        }
    }
    private Context mContext;
    private LayoutInflater mInflater;
    
    public RankingAdapter(Context context) {
        mContext = context;
        mInflater = LayoutInflater.from(context);
    }
    
    @Override
    public int getCount() {
        return LENGTH;
    }
    
    @Override
    public RankingItem getItem(int position) {
        if (position < 0 || position >= LENGTH) return null;
        return ITEMS.get(position);
    }
    
    @Override
    public long getItemId(int position) {
        return position;
    }
    
    @Override
    public View getView(int position, View convertView, ViewGroup root) {
        View view;
        
        if (convertView == null) {
            view = mInflater.inflate(R.layout.ranking_item, null);
            view.setTag(new ItemHolder(view));
        } else {
            view = convertView;
        }
        renderItem(view, getItem(position));
        
        return view;
    }
    
    private void renderItem(View view, RankingItem item) {
        if (item == null) return;
        ItemHolder holder = (ItemHolder) view.getTag();
        
        holder.mRank.setText(item.rank);
        holder.mName.setText(item.name);
        holder.mCal.setText(item.cal);
    }
    
    private static final class ItemHolder {
        TextView mName;
        TextView mRank;
        TextView mCal;
        private ItemHolder(View view) {
            mRank = get(view, R.id.rank);
            mName = get(view, R.id.name);
            mCal = get(view, R.id.cal);
        }
        
        @SuppressWarnings("unchecked")
        <V extends View> V get(View view, int id) {
            return (V) view.findViewById(id);
        }
    }
}
